package com.xbongbong.saas.model.impl;/*/*/

import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.WorkOrderStageDao;
import com.xbongbong.saas.domain.entity.WorkOrderStageEntity;
import com.xbongbong.saas.model.WorkOrderStageModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 *
 * @author 魏荣杰
 * @date 2019/3/7 14:46
 * @since v1.0
 * @version v1.0
 */
@Service("workOrderStageModel")
public class WorkOrderStageModelImpl implements WorkOrderStageModel {
    @Resource
    private WorkOrderStageDao workOrderStageDao;

    @Override
    public Integer insert(WorkOrderStageEntity entity) throws XbbException {
        Long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return workOrderStageDao.insert(entity);
    }

    @Override
    public Integer update(WorkOrderStageEntity entity) throws XbbException {
        entity.setUpdateTime(DateTimeUtil.getInt());
        return workOrderStageDao.update(entity);
    }

    @Override
    public List<WorkOrderStageEntity> findEntitys(Map<String, Object> param) {
        return workOrderStageDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return workOrderStageDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer save(WorkOrderStageEntity entity) throws XbbException {
        if (entity.getId() == null || Objects.equals(0L, entity.getId())) {
            return insert(entity);
        }
        return update(entity);
    }

    @Override
    public Integer delete(Map<String, Object> param) {
        return workOrderStageDao.delete(param);
    }

    @Override
    public WorkOrderStageEntity getNextStage(Map<String, Object> param) {
        return workOrderStageDao.getNextStage(param);
    }

    @Override
    public WorkOrderStageEntity getByKey(Long stageId, String corpid) {
        return workOrderStageDao.getByKey(stageId,corpid);
    }

    @Override
    public List<WorkOrderStageEntity> workOrderStageListByTemplateId(String corpid, Long templateId) {
        Map<String, Object> param = new HashMap<>(4);
        param.put("corpid", corpid);
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("templateId", templateId);
        param.put("orderByStr", "sort");
        return findEntitys(param);
    }

    @Override
    public WorkOrderStageEntity getPreStage(Map<String, Object> param) {
        return workOrderStageDao.getPreStage(param);
    }

    @Override
    public List<Long> getPreStageList(Map<String, Object> param) {
        return workOrderStageDao.getPreStageList(param);
    }

    @Override
    public WorkOrderStageEntity getFirstStage(Long templateId, String corpid) {
        return workOrderStageDao.getFirstStage(templateId,corpid);
    }
    /**
     * 批量删除
     * @param list 主键id集合
     * @param corpid
     * @author xingxing.xiao
     */
    @Override
    public Integer deleteBatch(List<Long> list, String corpid) {
        return workOrderStageDao.deleteBatch(list, corpid);
    }

    @Override
    public void updateBatch(List<WorkOrderStageEntity> entities, String corpid) {
        workOrderStageDao.updateBatch(entities,corpid);
    }
}
